<!-- 群控管理 -->
<template>
  <el-dialog v-if="props.show" :model-value="props.show" :title="t('690')" :close-on-click-modal="false"
    :close-on-press-escape="false" top="12vh" width="60%" @close="onHideDetails">
    <template #header>
      <div class="box-title flex">
        {{t('690')}}
        <el-tooltip class="icon-item" :content="t('691')" placement="top">
          <el-button class="marginL10" icon="Refresh" type="success" @click="getSearchList">{{t('88')}}</el-button>
        </el-tooltip>
      </div>
    </template>
    <div class="dialogMax" style="overflow: auto;">
      <p>
        {{t('692')}}<span class="box-title marginR30">{{ data.detailsInfo.now_number_data.game_number }}</span>
        <span class="mustPass" :class="data.countDown?'colorGreen':''">{{ data.countDown > 0?t('693'):t('694')}}：{{ data.countDown>0?data.countDown:data.awaitCountDown }}</span>
        <span class="tipsTextRed">{{ data.isShowResult?t('695'):t('696') }}</span>
      </p>
      <p>
        {{t('697')}}：<span class="marginR30" :class="colorClass(data.detailsInfo.total_game_income)">{{ BigWan(data.detailsInfo.total_game_income) }}</span>
        {{t('698')}}：<span class="marginR30" :class="colorClass(data.detailsInfo.water_level)">{{ BigWan(data.detailsInfo.water_level) }}</span>
        {{t('699')}}：<span class="marginR30 colorGre">{{ BigWan(data.detailsInfo.total_game_bet) }}</span>
        {{t('700')}}：<span class="box-title">{{ data.detailsInfo.before_open_number }}</span>
      </p>
      <p>
        {{t('701')}}：<span class="marginR30 colorText">{{ BigWan(data.detailsInfo.current_number_data.bet) }}</span>
        {{t('702')}}：<span class="marginR30 colorText">{{ data.detailsInfo.current_number_data.bet_count }}</span>
        {{t('703')}}：<span class="marginR30 colorText">{{ data.detailsInfo.current_number_data.bet_person }}</span>
      </p>
      <p>
        {{t('704')}}：<span class="marginR30 colorText">{{ BigWan(data.detailsInfo.before_number_data.bet) }}</span>
        {{t('705')}}：<span class="marginR30 colorText">{{ data.detailsInfo.before_number_data.bet_count }}</span>
        {{t('706')}}：<span class="marginR30 colorText">{{ data.detailsInfo.before_number_data.bet_person }}</span>
      </p>
      <p>
        {{t('707')}}：<span class="marginR30 colorText">{{ BigWan(data.detailsInfo.future_number_data.bet) }}</span>
        {{t('708')}}：<span class="marginR30 colorText">{{ data.detailsInfo.future_number_data.bet_count }}</span>
        {{t('709')}}：<span class="marginR30 colorText">{{ data.detailsInfo.future_number_data.bet_person }}</span>
        <span class="marginR30 item_details" @click="getSearchDetailsList">{{t('710')}}</span>
      </p>
      <div class="flex marginTB10">
        <el-button :type="data.typeIndex == 1 ? 'warning' : ''" @click="chooseType(1)">{{t('711')}}</el-button>
        <el-button :type="data.typeIndex == 2 ? 'warning' : ''" @click="chooseType(2)">{{t('712')}}</el-button>
        <el-button :type="data.typeIndex == 3 ? 'warning' : ''" @click="chooseType(3)">{{t('713')}}</el-button>
      </div>
      <!-- 新增控制 -->
      <el-button type="success" :disabled="!data.typeIndex?true:false" @click="data.isShowControl = true">{{t('714')}}</el-button>
      <!-- 控制详情 -->
      <SearchTable :query="data.query" :list="data.list" :total="data.total" :showSet="false"
        @changeSize="changeSize" @changePage="changePage" @search="getActionList" @reset="resetDetails()" style="height: 86%;">
        <template #form>
          <el-form-item :label="t('715')+'：'">
            <el-input type="number" class="width200" v-model="data.query.game_number" :min="0" :max="99999999999999999" :placeholder="t('19')+t('715')" clearable onkeyup="this.value=this.value.replace(/\D/g,'')"/>
          </el-form-item>
          <el-form-item :label="t('20')+'：'">
            <el-select v-model="data.query.action_status" :placeholder="t('340')" filterable>
              <el-option :label="t('21')" :value="-1" />
              <el-option v-for="item in data.statusList" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item :label="t('17')+'：'" v-if="data.typeIndex==2?true:false">
            <el-input type="number" class="width200" v-model="data.query.account_id" :min="0" :max="99999999999999999" :placeholder="t('19')+t('17')" clearable onkeyup="this.value=this.value.replace(/\D/g,'')"/>
          </el-form-item>
        </template>
        <template #button></template>
        <template #table>
          <template v-for="(item, index) in data.fields" :key="index">
            <el-table-column v-if="item.visible" :prop="item.prop" :label="item.label" :width="item.width" show-overflow-tooltip>
              <template v-if="item.prop == 'game_number'" #default="scope">
                {{ scope.row.game_number ? scope.row.game_number : t('716')  }}
              </template>
              <template v-if="item.prop == 'action_account_id'" #default="scope">
                {{ scope.row.action_account_id ? scope.row.action_account_id : t('716')  }}
              </template>
              <template v-if="item.prop == 'action_status'" #default="scope">
                <el-tag :type="scope.row.action_status == 1 ? 'success' : scope.row.action_status == 2 ?'warning': scope.row.action_status == 3 ?'danger':'info'">
                  {{ selectToLabel(data.statusList,scope.row.action_status) }}
                </el-tag>
              </template>
              <template v-if="item.prop == 'action_details'" #default="scope">
                <el-tag v-if="scope.row.action_type!=3" :type="scope.row.action_details==1 ? 'success' : 'danger'">
                {{ selectToLabel(scope.row.action_type==1?data.systemDetailsList:data.actionDetailsList,scope.row.action_details) }}
                </el-tag>
                <span v-else>{{ scope.row.action_details }}</span>
              </template>
              <template v-if="item.prop == 'lottery'" #default="scope">
                <span v-if="scope.row.action_global">-</span>
                <el-tag v-else-if="scope.row.action_type!=3" :type="scope.row.action_details==1 ? 'success' : 'danger'">
                {{ selectToLabel(scope.row.action_type==1?data.systemDetailsList:data.actionDetailsList,scope.row.action_details) }}
                </el-tag>
                <span v-else>{{ scope.row.action_details }}</span>
              </template>
              <template v-if="item.prop == 'fail_desc'" #default="scope">
                <span v-if="scope.row.action_global">-</span>
                <span v-else-if="scope.row.luck_issue?.fail_desc">{{ scope.row.luck_issue?.fail_desc }}</span>
                <el-tag v-else-if="scope.row.action_type!=3 && !scope.row.luck_issue?.fail_desc" :type="scope.row.action_details==1 ? 'success' : 'danger'">
                  {{ selectToLabel(scope.row.action_type==1?data.systemDetailsList:data.actionDetailsList,scope.row.action_details) }}
                </el-tag>
              </template>
              <template v-if="item.prop == 'action_time'" #default="scope">
                {{ setTimestampTime(scope.row.action_time) }}
              </template>
            </el-table-column>
          </template>
          <el-table-column fixed="right" :label="t('97')" width="90" align="center">
            <template #default="scope">
              <el-button @click="deleteAction(scope.row)" type="danger" size="small" >
                {{ t('636') }}
              </el-button>
            </template>
          </el-table-column>
        </template>
      </SearchTable>
    </div>
  </el-dialog>
  <!-- 新增控制 -->
  <el-dialog v-model="data.isShowControl" width="50%" :title="t('717')" :close-on-click-modal="false"
    :close-on-press-escape="false" @close="close" top="30vh">
    <template #header>
      <span class="box-title">{{t('718')}}<span class="mustPass">{{ data.typeIndex==1?t('711'):data.typeIndex==2?t('712'):t('713') }}</span></span>
    </template>
    <el-form ref="ruleFormRef" :model="data.formParams" :inline="true">
      <form-item :title="t('719')" value="action_global" v-show="data.typeIndex != 3? true : false" >
        <el-radio-group v-model="data.formParams.action_global" size="large">
          <el-radio-button :label="t('720')" :value="0" />
          <el-radio-button :label="t('716')" :value="1" />
        </el-radio-group>
      </form-item>
      <form-item :title="t('715')" :pass="true" value="game_number" v-show="!data.formParams.action_global ? true : false">
        <el-input type="number" class="width200" v-model="data.formParams.game_number" :min="0" :max="99999999999999999" :placeholder="t('19')+t('715')" clearable onkeyup="this.value=this.value.replace(/\D/g,'')"/>
        <span class="tipsTextRed">{{t('721')}}【{{ data.maxGameNumber }}】</span>
      </form-item>
      <el-form-item :title="t('17')+'：'" :pass="true" value="action_account_id" v-show="data.typeIndex == 2 ? true : false">
        <el-input type="number" class="width200" v-model="data.formParams.action_account_id" :min="0" :max="99999999999999999" :placeholder="t('19')+t('17')" clearable onkeyup="this.value=this.value.replace(/\D/g,'')"/>
        <p class="tipsTextRed">({{ t('722') }})</p>
      </el-form-item>
      <form-item :title="data.formParams.action_global?t('723'):t('724')" :pass="true" value="action_details" v-show="data.typeIndex != 3 ? true : false">
        <el-select v-model="data.formParams.action_details" :placeholder="t('340')" filterable>
          <el-option v-for="item in data.typeIndex==1?data.systemDetailsList:data.actionDetailsList" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
        <span v-show="data.formParams.action_global" class="tipsTextRed">({{ t('725') }})</span>
      </form-item>
      <form-item :title="t('726')+'：'" :pass="true" value="game_number" v-show="data.typeIndex == 3 ? true : false">
        <el-select v-model="data.formParams.action_details" :placeholder="t('340')" filterable>
          <el-option v-for="item in 49" :key="item" :label="item" :value="item" />
        </el-select>
        <span class="tipsTextRed">({{ t('727') }})</span>
      </form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button type="info" @click="close">{{t('240')}}</el-button>
        <el-button type="primary" @click="addControl">{{t('241')}}</el-button>
      </div>
    </template>
  </el-dialog>
  <!-- 玩家下注详情 -->
  <el-dialog v-model="data.isShowDetails" width="80%" :title="t('710')" :close-on-click-modal="false"
    :close-on-press-escape="false" @close="close" top="10vh">
    <div class="dialogMaxQuery" style="overflow: auto;">
      <SearchTable :query="data.queryDetails" :list="data.listDetails" :total="data.totalDetails" :showSet="false"
        @changeSize="changeSizeDetails" @changePage="changePageDetails" @reset="resetDetails" @search="getSearchDetailsList">
        <template #form>
          <el-form-item label="">
            {{t('692')}}：<span class="box-title marginR20">{{ data.detailsInfo.now_number_data.game_number }}</span>
            <span class="mustPass" :class="data.countDown?'colorGreen':''">{{ data.countDown > 0?t('693'):t('694')}}：{{ data.countDown>0?data.countDown:data.awaitCountDown }}</span>
          </el-form-item>
          <el-form-item :label="t('17')+'：'">
            <el-input class="width200" type="text" v-model="data.queryDetails.account_id" :placeholder="t('19')+t('17')" clearable />
          </el-form-item>
          <el-form-item :label="t('18')+'：'">
            <el-input class="width200" type="text" v-model="data.queryDetails.account" :placeholder="t('19')+t('18')" clearable />
          </el-form-item>
          <el-form-item :label="t('728')+'：'">
            <el-select v-model="data.queryDetails.state" :placeholder="t('340')">
              <el-option :label="t('21')" :value="-1" />
              <el-option v-for="item in data.userDetailsList" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="">
            <el-select class="selectWidth150" v-model="data.queryDetails.time_type" :placeholder="t('340')">
              <el-option :label="t('729')" :value="1" />
              <el-option :label="t('730')" :value="2" />
            </el-select>
            <el-date-picker v-model="data.queryDetails.date" type="daterange" range-separator="-" :start-placeholder="t('26')"
              :end-placeholder="t('27')" value-format="YYYY-MM-DD" clearable :disabled-date="indexStore.disabledDateTime"/>
          </el-form-item>
        </template>
        <template #table>
          <template v-for="(item, index) in data.fieldDetails" :key="index">
            <el-table-column v-if="item.visible" :prop="item.prop" :label="item.label" :width="item.width" show-overflow-tooltip>
              <template v-if="item.prop == 'state'" #default="scope">
                <el-tag :type="scope.row.state == 1 ? 'success' : scope.row.state == 2 ?'info':'danger'">
                  {{ selectToLabel(data.userDetailsList,scope.row.state) }}
                </el-tag>
              </template>
              <template v-if="item.prop == 'action_details'" #default="scope">
                <el-tag v-if="scope.row.action_type!=3" :type="scope.row.action_details==4 ? 'danger' : 'success'">
                {{ selectToLabel(scope.row.action_type==1?data.systemDetailsList:data.actionDetailsList,scope.row.action_details) }}
                </el-tag>
                <span v-else>{{ scope.row.action_details }}</span>
              </template>
              <template v-if="item.prop == 'open_number'" #default="scope">
                {{ scope.row.open_number?scope.row.open_number:'-' }}
              </template>
              <template v-if="item.prop == 'bet'" #default="scope">
                <span class="colorText">{{ BigWan(scope.row.bet) }}</span>
              </template>
              <template v-if="item.prop == 'user_amount_after'" #default="scope">
                <span class="colorText">{{ BigWan(scope.row.user_amount_after) }}</span>
              </template>
              <template v-if="item.prop == 'win_lose'" #default="scope">
                <span :class="colorClass(BigMinus(BigWan(scope.row.win),BigWan(scope.row.bet)))">{{ scope.row.state==1?BigMinus(BigWan(scope.row.win),BigWan(scope.row.bet)):'-' }}</span>
              </template>
              <template v-if="item.prop == 'win'" #default="scope">
                <span class="colorText">{{ BigWan(scope.row.win)?BigWan(scope.row.win):'-' }}</span>
              </template>
              <template v-if="item.prop == 'bet_time'" #default="scope">
                {{ setTimestampTime(scope.row.bet_time) }}
              </template>
              <template v-if="item.prop == 'result_time'" #default="scope">
                {{ setTimestampTime(scope.row.result_time) }}
              </template>
            </el-table-column>
          </template>
        </template>
      </SearchTable>
    </div>
  </el-dialog>
</template>

<script lang="ts" setup>
import { ref, reactive, onBeforeUnmount, watch, computed, unref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import SearchTable from '@/components/SearchTable/SearchTable.vue'
import FormItem from '@/components/FormItem/FormItem.vue'
import { throttle, selectToLabel, colorClass } from '@/utils/index'
import { BigWan, BigMinus, BigInteger } from '@/utils/math'
import { getDateDay, setTimestampTime, setTimeValue } from '@/utils/time'
import { 
getPeriodDetails,
checkAction,
addLuckAction,
deleteLuckAction,
getLuckAction,
getLuckBet 
} from '@/api/game'

import { useI18n } from 'vue-i18n'
const { t } = useI18n()
import { useStore } from '@/stores/index'
const indexStore = useStore()

const props = defineProps({
  show: {
    type: Boolean,
    default: () => {
      return false
    }
  },
  checkedItem: {
    type: Object,
    default: () => {
      return {}
    }
  }
})

watch(
  () => [props.checkedItem, props.show],
  async (value) => {
    if (value[1]) {
      data.typeIndex = 0
      getSearchList()
    }
  },
)

const data = reactive({
  query: {
    page: 1,
    size: 50,
    agent_id: -1,
    action_type: 0,
    action_status: -1,
    game_number: '',
    account_id: '',
    start_time: 0,
    end_time: 0,
  },
  list: [],
  total: 0,
  fields: [
    { label: t('731'), prop: 'game_number', width: '', visible: true },
    { label: t('20'), prop: 'action_status', width: '120', visible: true },
    { label: t('735'), prop: 'action_details', width: '120', visible: true },
    { label: t('736'), prop: 'lottery', width: '', visible: true },
    { label: t('505'), prop: 'fail_desc', width: '120', visible: true },
    { label: t('737'), prop: 'action_admin_name', width: '100', visible: true },
    { label: t('738'), prop: 'action_time', width: '', visible: true },
  ],
  queryDetails:{
    page: 1,
    size: 50,
    account_id: '',
    account: '',
    state: -1,
    time_type: 1,
    game_number: '',
    date: [getDateDay(0),getDateDay(0)],
  },
  listDetails: [],
  totalDetails: 0,
  fieldDetails: [
    { label: t('715'), prop: 'account_id', width: '120', visible: true },
    { label: t('18'), prop: 'account', width: '150', visible: true },
    { label: t('731'), prop: 'game_number', width: '120', visible: true },
    { label: t('728'), prop: 'state', width: '120', visible: true },
    { label: t('732'), prop: 'order_id', width: '100', visible: true },
    { label: t('733'), prop: 'bet_number', width: '100', visible: true },
    { label: t('726'), prop: 'open_number', width: '100', visible: true },
    { label: t('44'), prop: 'bet', width: '120', visible: true },
    { label: t('734'), prop: 'user_amount_after', width: '200', visible: true },
    { label: t('45'), prop: 'win_lose', width: '120', visible: true },
    { label: t('51'), prop: 'win', width: '120', visible: true },
    { label: t('729'), prop: 'bet_time', width: '150', visible: true },
    { label: t('730'), prop: 'result_time', width: '150', visible: true }
  ],
  isShowDetails: false,
  isShowControl: false,
  isShowResult: false,
  statusList:[
    { label: t('739'), value: 0 },
    { label: t('740'), value: 1 },
    { label: t('741'), value: 2 },
    { label: t('742'), value: 3 },
    { label: t('743'), value: 4 },
  ],
  systemDetailsList:[
    { label: t('744'), value: 1 },
    { label: t('745'), value: 2 }
  ],
  actionDetailsList:[
    { label: t('747'), value: 1 },
    { label: t('748'), value: 2 }
  ],
  userDetailsList:[
    { label: t('749'), value: 0 },
    { label: t('750'), value: 1 },
    { label: t('751'), value: 2 },
    { label: t('752'), value: 3 },
    { label: t('753'), value: 4 },
  ],
  detailsInfo: {
    total_game_income: 0, //总输赢
    total_game_bet: 0, //总下注
    water_level: 0, //游戏水位
    before_open_number: 0, //上一期开奖数字
    now_number_data: { //当前期的信息
      game_number: 0,
      draw_time: 0,//下注结束时间
      award_ts: 0,//开奖时间
    },
    current_number_data: { //当前期的数据
      bet: 0, //下注金额
      bet_count: 0, //下注单数
      bet_person: 0, //下注人数
    },
    before_number_data: { //上一期的数据
      bet: 0, //下注金额
      bet_count: 0, //下注单数
      bet_person: 0, //下注人数
    },
    future_number_data: { //将来期的数据
      bet: 0, //下注金额
      bet_count: 0, //下注单数
      bet_person: 0, //下注人数
    },
    action_effective_type: 0,// 风控 查询生效中的类型 0是未控制 1是控系统 2是控玩家 3是控数字
    luck_config:{} as any //群控信息
  },
  formParams: {
    agent_id: 0,
    game_id: 0,
    action_type: 0,
    action_global: 0,
    game_number: '',
    action_account_id: '',
    action_details: 1,
  },
  time: null as any,
  interval: null as any,
  awaitInterval: null as any,
  countDown: 60,
  awaitCountDown: 0,
  typeIndex: 0,
  maxGameNumber: 0,
})

const getSearchList = async () => {
  let details = await getPeriodDetails({agent_id:props.checkedItem.agent_id,game_id:props.checkedItem.game_id});
  console.log('调控详情','开奖结束时间'+setTimestampTime(details.data.now_number_data.draw_time),'当前时间'+setTimestampTime(Date.now()/1000),details);
  data.detailsInfo = details.data
  data.maxGameNumber = data.detailsInfo.now_number_data.game_number + data.detailsInfo.luck_config.a_hundred_prebetting
  // 控制类型覆盖
  if(details.data.action_effective_type){
    data.query.action_type = details.data.action_effective_type
  }else{
    data.query.action_type = 0
  }
  // 如果当前选择的控制类型与返回的不一致 以当前选择的为准
  if(details.data.action_effective_type && !data.typeIndex){
    chooseType(details.data.action_effective_type)
  }else{
    getActionList()
  }
  closeInterval()
  betTimeInterval(details.data.now_number_data.draw_time)
  if(data.isShowDetails){
    getSearchDetailsList()
  }
}

// 操作记录
const getActionList = async () => {
  let query=JSON.parse(JSON.stringify(data.query));
  query.agent_id = props.checkedItem.agent_id
  query.action_type = data.typeIndex
  query.game_number = Number(query.game_number)
  query.account_id = Number(query.account_id)
  query.game_id = props.checkedItem.game_id
  let res = await getLuckAction(query);
  data.list = res.data.list
  data.total = res.data.total
}

// 玩家下注详情
const getSearchDetailsList = async () => {
  data.isShowDetails = true
  let query=JSON.parse(JSON.stringify(data.queryDetails));
  query=setTimeValue(query)
  query.agent_id = props.checkedItem.agent_id
  query.game_id = props.checkedItem.game_id
  let res = await getLuckBet(query);
  data.listDetails = res.data.list
  data.totalDetails = res.data.total
}

// 选择控制类型
const chooseType = (type: number) => {
  if(type){
    data.typeIndex = type
  }
  data.formParams.game_number = ''
  data.formParams.action_account_id = ''
  data.formParams.action_details = 1
  getActionList()
  data.fields = [
    { label: t('731'), prop: 'game_number', width: '', visible: true },
    { label: t('17'), prop: 'action_account_id', width: '', visible: data.typeIndex == 2?true:false },
    { label: t('726'), prop: 'action_details', width: '120', visible: data.typeIndex == 3?true:false },
    { label: t('20'), prop: 'action_status', width: '120', visible: true },
    { label: t('735'), prop: 'action_details', width: '120', visible: true },
    { label: t('736'), prop: 'lottery', width: '', visible: true },
    { label: t('505'), prop: 'fail_desc', width: '100', visible: true },
    { label: t('737'), prop: 'action_admin_name', width: '100', visible: true },
    { label: t('738'), prop: 'action_time', width: '', visible: true },
  ]
}

// 新增控制
const addControl = throttle(async() => {
  let query=JSON.parse(JSON.stringify(data.formParams)),messageId=t('19')+t('17'),messageNum=t('19')+t('715');
  query.action_type = data.typeIndex
  query.agent_id = props.checkedItem.agent_id
  query.game_id = props.checkedItem.game_id
  // 控全局
  if(data.formParams.action_global){
    query.game_number = ''
    if(data.typeIndex!=2){
      query.action_account_id = ''
    }else if(!query.action_account_id) return ElMessage.error(messageId)
  }else{
    // 控系统输赢
    if(data.typeIndex == 1){
      if(!query.game_number) return ElMessage.error(messageNum)
    }
    // 控玩家输赢
    if(data.typeIndex == 2){
      if(!query.game_number) return ElMessage.error(messageNum)
      if(!query.action_account_id) return ElMessage.error(messageId)
    }
    // 控开奖数字
    if(data.typeIndex == 3){
      if(!query.game_number) return ElMessage.error(messageNum)
    }
    if(query.game_number && query.game_number<data.detailsInfo.now_number_data.game_number){
      return ElMessage.error(t('754'))
    }
    if(query.game_number>data.maxGameNumber){
      return ElMessage.error(t('755')+data.maxGameNumber)
    }
  }
  query.game_number = Number(query.game_number)
  // 查询输入期数或者数字是否有同期或者交叉影响
  let res = await checkAction(query),msg='';
  if(!res.data.length){
    let result = await addLuckAction(query)
    data.isShowControl = false
    ElMessage.success(t('756'))
    getActionList()
  }else{
    // 先有控全局-后有期数或者玩家或者数字
    if(res.data[0].action_global==1 && !data.formParams.action_global){
      return ElMessage.error(t('757'))
    }else{
      msg=t('758')
    }
    ElMessageBox.confirm(msg, t('650'), {
      confirmButtonText: t('241'),
      cancelButtonText: t('240')
    }).then(async () => {
      data.isShowControl = false
      let result = await addLuckAction(query)
      ElMessage.success(t('756'))
      getActionList()
    }).catch(() => {})
  }
}, 3000)

// 删除控制
const deleteAction = throttle(async(row:any) => {
  ElMessageBox.confirm(t('759'), t('650'), {
    confirmButtonText: t('241'),
    cancelButtonText: t('240')
  }).then(async () => {
    let res = await deleteLuckAction({id:row.id})
    ElMessage.success(t('760'))
    getActionList()
  }).catch(() => {})
}, 2000)


// 开奖倒计时
const betTimeInterval = async (endTime:number) => {
  let nowTime = BigInteger((Date.now()/1000)) as number;
  data.countDown = BigMinus(endTime,nowTime)
  if(BigMinus(endTime,nowTime) <= -1){
    closeInterval()
    data.countDown = 0
    data.isShowResult = true
    return  ElMessage.error(t('761'))
  }else{
    data.isShowResult = false
    getNewData()
    timeInterval()
  }
}
const timeInterval = () => {
  data.interval = setInterval(() => {
    data.countDown -= 1
    if (data.countDown < 0 ) {
      data.awaitCountDown = 9
      closeInterval()
      awaitTimeInterval()
    }
  }, 1000)
}
// 等待倒计时
const awaitTimeInterval = () => {
  data.awaitInterval = setInterval(() => {
    data.awaitCountDown -= 1
    // 时间跟游戏结算差1秒
    if (data.awaitCountDown < 0 ) {
      data.awaitCountDown = 0
      getSearchList() //获取详情
    }
    // 时间跟游戏一致
    // if (data.awaitCountDown < 0 ) {
    //   data.awaitCountDown = 0
    //   getSearchList() //获取详情
    // }
  }, 1000)
}
// 10秒重新请求一当前数据
const getNewData = () => {
  data.time = setInterval(async () => {
    getSearchList()
  }, 1000 * 10)
}
// 清除定时器
const closeInterval = () => {
  clearInterval(data.awaitInterval)
  clearInterval(data.interval)
  clearInterval(data.time)
}

// 修改页数
const changeSize = (val: number) => {
  data.query.size = val
}
const changePage = (val: number) => {
  data.query.page = val
  getActionList()
}
const changePageDetails = (val: number) => {
  data.queryDetails.page = val
  getSearchDetailsList()
}
const changeSizeDetails = (val: number) => {
  data.queryDetails.size = val
}

onBeforeUnmount(() => {
  closeInterval()
})
// 重置
const close = () => {
  data.isShowDetails = false
  data.isShowControl = false
}
const emit = defineEmits(['onHideDetails'])
const onHideDetails = () => {
  closeInterval()
  emit('onHideDetails', false)
}
const resetDetails = () => {
  if(data.isShowDetails){
    data.queryDetails = {
      page: 1,
      size: 50,
      account_id: '',
      account: '',
      state: -1,
      time_type: 1,
      game_number: '',
      date: [getDateDay(0),getDateDay(0)],
    }
  }else{
    data.query ={
      page: 1,
      size: 50,
      agent_id: -1,
      action_type: 0,
      action_status: -1,
      game_number: '',
      account_id: '',
      start_time: 0,
      end_time: 0,
    }
  }
  getSearchList()
}
</script>

<style scoped lang="scss">
.icon-item{
  margin-left: 10px;
  cursor: pointer;
}
.icon-item :hover{
  scale: (1.2);
  all: inherit 0.1s;
}
.dialogMax {
  padding-top: -20px;
  font-size: 16px;
  font-weight: 600;
  line-height: 40px;
  .box-control {
    margin-top: 10px;
    border: 1px solid #cdcdcd;
    border-radius: 5px;
    padding:5px 10px;
    line-height: 50px;
    background-color: #ededed;
  }
  .btnDanger{
    background-color: #F56C6C;
  }
  .btnSuccess{
    background-color: #67C23A;
  }
}
</style>